/*THIS RUNS THROUGH THE RESULTS IN BLOOM AND VAN REENEN QJE "Managemnet practices..."*/
/*JANUARY 2007*/

cap log close
clear
set memory 250m
set more 1
****RUN THE RESULTS USING THE REAL DATA
cap log using realdata,replace t
u realdata,clear

*set macros
mac def noise "gender sen1 tenurep countries day2 day3 day4 day5 timelocal  duration reli aa*  "
*note we use log(hrs) not level of hours as before
mac def extras "uncons lfirmage public uncons ldegree* mba* lhrs*  "

ge probyr=year==.
egen mprobyr=max(probyr),by(code)

so code
keep if code~=code[_n-1]

*****************FIGURE 1
histogram amanagement if cty=="fr",bin(50) ylabel(0 0.2 0.4 0.6 0.8 1.0 1.2)
*graph export "D:\data\Management\QJE\Figure1a.tif", as(tif) preview(on) replace
histogram amanagement if cty=="gr",bin(50) ylabel(0 0.2 0.4 0.6 0.8 1.0 1.2)
*graph export "D:\data\Management\QJE\Figure1b.tif", as(tif) preview(on) replace
histogram amanagement if cty=="uk",bin(50) ylabel(0 0.2 0.4 0.6 0.8 1.0 1.2)
*graph export "D:\data\Management\QJE\Figure1c.tif", as(tif) preview(on) replace
histogram amanagement if cty=="us",bin(50) ylabel(0 0.2 0.4 0.6 0.8 1.0 1.2)
*graph export "D:\data\Management\QJE\Figure1d.tif", as(tif) preview(on) replace

*****************FIGURE 2
histogram amanagement if (famcontrol50_2ceop==1|competition<=2)&famceomiss==0,bin(50) ylabel(0 0.2 0.4 0.6 0.8 1.0 1.2)
*graph export "D:\data\Management\QJE\Figure2.tif", as(tif) preview(on) replace
gen low=(amanagement<=2)
su low if (famcontrol50_2ceop==1|competition<=2)&famceomiss==0

*****************FIGURE 3
histogram amanagement if (famcontrol50_2ceop==0&competition==3)&famceomiss==0,bin(50) ylabel(0 0.2 0.4 0.6 0.8 1.0 1.2)
*graph export "D:\data\Management\QJE\Figure3.tif", as(tif) preview(on) replace
su low if (famcontrol50_2ceop==0&competition==3)&famceomiss==0

******************************************************************************************************
*********************************************TABLE I*****************************************
******************************************************************************************************
u realdata,replace
set more 1
egen lp_av=mean(lp),by(code)
egen le_av=mean(le),by(code)
egen lm_av=mean(lm),by(code)
egen roce_av=mean(roce),by(code)

so code year
gen x=(code~=code[_n+1])
egen snoj=sum(x),by(sic3)
drop x


*Col 1
reg ls zmanagement le le_f le_g le_un le_us uncons cyy* if lm~=.&lp~=.,rob cluster(code)
*Col 2 - Standard
reg ls zmanagement le lm  lp   lp_f lp_g lp_un lp_us  le_f le_g le_un le_us  lm_f lm_g lm_un lm_us uncons cyy* ,rob cluster(code)
*Col 3 - Standard
areg ls zmanagement le lm  lp   lp_f lp_g lp_un lp_us  le_f le_g le_un le_us  lm_f lm_g lm_un lm_us cyy* $extras,ab(sic3) rob cluster(code)
*Col 4 - Standard
areg ls zmanagement lp le lm lp_f lp_g lp_un lp_us  le_f le_g le_un le_us  lm_f lm_g lm_un lm_us  $noise  cyy* $extras    ,ab(sic3) rob cluster(code)
*Col 5 - USE BVR_OP3.DO 
*Col 6 
areg roce zmanagement lp le lm  lp_f lp_g lp_un lp_us  le_f le_g le_un le_us  lm_f lm_g lm_un lm_us  $noise  cyy* $extras    ,ab(sic3) rob cluster(code)
*Col 7
areg lq zmanagement lp le lm lp_f lp_g lp_un lp_us  le_f le_g le_un le_us  lm_f lm_g lm_un lm_us  $noise  cyy* $extras    ,ab(sic3) rob cluster(code)
*Col 8
keep if lm~=.
keep if lp~=.
keep if code~=code[_n+1]
dprobit dead amanagement le lp lm lfirmage public ccuk ccfr ccge if code~=code[_n+1]
cap drop coeff* mdead
matrix x=e(dfdx)
svmat x,name(coeffs)
egen mdead =mean(dead) 
di coeffs1/mdead
di coeffs2/mdead
di coeffs3/mdead
di coeffs4/mdead


u realdata,replace
set more 1
gen x=(code~=code[_n+1])
egen snoj=sum(x),by(sic3)
drop x

*column 9 - standard
areg dsales zmanagement lp le lm lp_f lp_g lp_un lp_us  le_f le_g le_un le_us  lm_f lm_g lm_un lm_us  $noise  cyy* $extras    ,ab(sic3) rob cluster(code)


******************************************************************************************************
*********************************************TABLE II*****************************************
******************************************************************************************************
egen zcapital=rmean(zlean1 zlean2 zperf2)
egen zhuman=rmean(ztalent1 ztalent6 ztalent7)
gen zhuman_zcapital=zhuman-zcapital
egen siczhuman_zcapital=mean(zhuman_zcapital),by(sic3)
so code year
keep if code!=code[_n+1]
*one missing value here
keep if uncons~=.

*Col 1 
reg zhuman ldegree* cc*,rob
*Col 2
reg zcapital ldegree* cc*,rob
*Col 3 - standard
reg zhuman_zcapital ldegree* cc*,rob
*Col 4
areg zhuman_zcapital ldegree* lempm lfirmage public cc*,ab(sic3) rob
*Col 5
areg zhuman_zcapital law lempm lfirmage public cc*,ab(sic3) rob


******************************************************************************************************
*********************************************TABLE III*****************************************
******************************************************************************************************
u realdata,replace
so code year
gen x=(code~=code[_n+1])
egen snoj=sum(x),by(sic3)
drop x
keep if code~=code[_n+1]
su zmanagement if uncons==. 
replace csic=oecdind_cty

*Col 1
areg zmanagement lindiopen9599,ab(cty) cluster(oecdind_cty)
*Col2
areg zmanagement lindiopen9599 lempm lfirmage public ldegree* mba* uncons ccfr ccge ccuk  $noise  if code~=code[_n+1],ab(sic3)rob cluster(oecdind_cty)
*Col 3
areg zmanagement lerner,ab(cty) cluster(csic)
*Col 4
areg zmanagement lerner        lempm lfirmage public ldegree* mba* uncons ccfr ccge ccuk  $noise  if code~=code[_n+1],ab(sic3)rob cluster(csic)
*Col 5
areg zmanagement competition*,ab(cty) 
*Col 6
areg zmanagement competition*  lempm lfirmage public ldegree* mba* uncons ccfr ccge ccuk  $noise  if code~=code[_n+1],ab(sic3)rob cluster(csic)
*Col 7
areg zmanagement lindiopen9599 lerner competition*,ab(cty) cluster(oecdind_cty)
*Col 8
areg zmanagement lindiopen9599 lerner competition*        lempm lfirmage public ldegree* mba* uncons ccfr ccge ccuk  $noise  if code~=code[_n+1],ab(sic3)rob cluster(oecdind_cty)



******************************************************************************************************
*********************************************TABLE IV*****************************************
******************************************************************************************************
*Note: famcontrol50 means family largest shareholder, famcontrol50_2ceo means also family ceo, familycontrol50_2ceop means also primogeniture. famcontrolmiss means missing ownership or ceo data.
*NOte: there is another variable (not used in the analysis) called famcontrol50_2 which if family ownership and family Ceo OR Chairman. The was accidently used before instead of famcontrol50
u realdata,replace
so code year
keep if code~=code[_n+1]

tab cty if famcontrolmiss==0,su(famcontrol50)
tab cty if famcontrolmiss==0,su(famcontrol50_2ceo)
tab cty if famcontrolmiss==0,su(famcontrol50_2ceop)
tab cty if famcontrolmiss==0,su(founder)
tab cty if famcontrolmiss==0,su(founderceo)


******************************************************************************************************
*********************************************TABLE V*****************************************
******************************************************************************************************
*Col 1
areg zmanagement famcontrol50 famcontrolmiss  lempm lfirmage public ldegree* mba* uncons ccfr ccge ccuk  $noise   if code~=code[_n+1],ab(sic3) rob
*Col 2
areg zmanagement famcontrol50_2ceo famcontrolmiss lempm lfirmage public ldegree* mba* uncons ccfr ccge ccuk  $noise  if code~=code[_n+1],ab(sic3)rob
*Col 3
areg zmanagement famcontrol50_2ceop famcontrolmiss lempm lfirmage public ldegree* mba* uncons ccfr ccge ccuk  $noise  if code~=code[_n+1],ab(sic3)rob
*Col 4
areg zmanagement famcontrol50_2ceop famcontrolmiss  if uncons~=.  ,ab(cty)
*Col 5
areg zmanagement famcontrol50 famcontrol50_2ceo famcontrol50_2ceop famcontrolmiss lempm lfirmage public ldegree* mba* uncons ccfr ccge ccuk  $noise  ,ab(sic3)rob
*Col 6
areg zmanagement famcontrol50 famcontrol50_2ceo famcontrol50_2ceop famcontrolmiss lempm lfirmage public ldegree* mba* uncons ccfr ccge ccuk  $noise  if type~=2&type~=4&type~=5&type!=6,ab(sic3)rob


******************************************************************************************************
**************************************TABLE VI***********************
******************************************************************************************************
u realdata,clear
so code year
keep if code~=code[_n+1]


*Column 1
reg amanagement ccge ccfr ccuk if uncons~=.,rob
*Column 2
reg amanagement ccge ccfr ccuk public lempm if uncons~=.,rob
*Column 3
reg amanagement ccge ccfr ccuk public lempm famcontrol50_2ceop famcontrolmiss if uncons~=.,rob
*Column 4
reg amanagement ccge ccfr ccuk public lempm competition* famcontrol50_2ceop famcontrolmiss if uncons~=.,rob
*Column 5
reg amanagement ccge ccfr ccuk public lempm competition* famcontrol50_2ceop famcontrolmiss ldegree* if uncons~=.,rob


******************************************************************************************************
**************************************APPENDIX I.C***********************
******************************************************************************************************

*Table A3, columns (1) (2) and (3)
u realdata,clear
so code
drop if code==code[_n+1]
foreach var in alean1 alean2 aperf1 aperf2 aperf3 aperf4 aperf5 aperf6 aperf7 aperf8 aperf9 aperf10 atalent1 atalent3 atalent4 atalent5 atalent6 atalent7{
qui egen _us`var'=mean(`var') if cty=="us"&code~=code[_n+1]
qui egen us`var'=max(_us`var')
qui gen norm`var'=`var'*100/us`var'
qui reg norm`var' ccuk ccge ccfr if code~=code[_n+1]
di " "
de `var'
di "Means for UK, Germany and France (US normalized to 100)"
di " "100+round(_b[ccuk]*10)/10 "    " 100+round(_b[ccge]*10)/10  "    " 100+round(_b[ccfr]*10)/10
di "SE for the means for UK, Germany and France (US normalized to 100)"
di " "round(_se[ccuk]*100)/100 "    " round(_se[ccge]*100)/100  "    " round(_se[ccfr]*100)/100
}

egen mus=mean(amanagement) if cty=="us"
egen m_us=max(mus)
gen ratio_us=100*amanagement/m_us
tab cty,su(ratio_us)

*Table A3, column (4)
u realdata,clear
so code year

foreach var in zlean1 zlean2 zperf1 zperf2 zperf3 zperf4 zperf5 zperf6 zperf7 zperf8 zperf9 zperf10 ztalent1 ztalent3 ztalent4 ztalent5 ztalent6 ztalent7{
qui areg ls `var'       lp le lm lp_f lp_g lp_un lp_us  le_f le_g le_un le_us  lm_f lm_g lm_un lm_us  $noise  cyy* $extras    ,ab(sic3) rob cluster(code)
de `var'
di "Point Estimate regression coefficient     " round(_b[`var']*1000)/1000
di "Standard Error of regression coefficient  " round(_se[`var']*1000) /1000
di "T-stat                                    " round((_b[`var']/_se[`var'])*100) /100
}




******************************************************************************************************
*********************************************TABLE A1*****************************************
******************************************************************************************************
u realdata,clear
ge empt=exp(lempm)

so code year
keep if uncons~=.
tab cty if code~=code[_n+1],su(zmanagement)
tab cty,su(emp)
tab cty if year==2002,su(tobinq)
tab cty,su(dsales)
tab cty if code~=code[_n+1],su(firmage)
tab cty if code~=code[_n+1],su(degree)
tab cty if code~=code[_n+1]&mbamiss==0,su(mba)
tab cty if code~=code[_n+1]&hourstmiss==0,su(hourst)
tab cty if code~=code[_n+1]&competitionmiss==0,su(competition)
tab cty if code~=code[_n+1],su(public)
gen _lerner=1-lerner
tab cty if code~=code[_n+1],su(_lerner)
drop if indiopen9599==.
tab cty if code~=code[_n+1],su(indiopen9599)


******************************************************************************************************
**************************************FOOTNOTES***********************
******************************************************************************************************
u realdata,clear
so code year
gen x=(code~=code[_n+1])
egen snoj=sum(x),by(sic3)
drop x

*FN 14
*Interaction for European management (note the UK is not truly a part of Europe....)
gen european=(cty=="fr"|cty=="ge")
gen european_management=european*zmanagement
areg ls zmanagement european_management lp le lm lp_f lp_g lp_un lp_us  le_f le_g le_un le_us  lm_f lm_g lm_un lm_us  $noise  cyy* $extras    ,ab(sic3) rob cluster(code)
/*drop next two from final version*/
areg ls zmanagement lp le lm lp_f lp_g lp_un lp_us  le_f le_g le_un le_us  lm_f lm_g lm_un lm_us  $noise  cyy* $extras     if european==0,ab(sic3) rob cluster(code)
areg ls zmanagement lp le lm lp_f lp_g lp_un lp_us  le_f le_g le_un le_us  lm_f lm_g lm_un lm_us  $noise  cyy* $extras     if european==1,ab(sic3) rob cluster(code)

*FN 16 and linked test (individual practices)
areg ls zoperations lp le lm lp_f lp_g lp_un lp_us  le_f le_g le_un le_us  lm_f lm_g lm_un lm_us  $noise  cyy* $extras    ,ab(sic3) rob cluster(code)
areg ls ztargets lp le lm lp_f lp_g lp_un lp_us  le_f le_g le_un le_us  lm_f lm_g lm_un lm_us  $noise  cyy* $extras    ,ab(sic3) rob cluster(code)
areg ls zmonitoring lp le lm lp_f lp_g lp_un lp_us  le_f le_g le_un le_us  lm_f lm_g lm_un lm_us  $noise  cyy* $extras    ,ab(sic3) rob cluster(code)
areg ls zincentives lp le lm lp_f lp_g lp_un lp_us  le_f le_g le_un le_us  lm_f lm_g lm_un lm_us  $noise  cyy* $extras    ,ab(sic3) rob cluster(code)

*FN 17
u realdata,clear
so code year
gen x=(code~=code[_n+1])
egen snoj=sum(x),by(sic3)
drop x
*R&D
areg ls zmanagement lgrd lp le lm lp_f lp_g lp_un lp_us  le_f le_g le_un le_us  lm_f lm_g lm_un lm_us  $noise  cyy* $extras   if lgrdmiss==0 ,ab(sic3) rob cluster(code)
areg ls zmanagement      lp le lm lp_f lp_g lp_un lp_us  le_f le_g le_un le_us  lm_f lm_g lm_un lm_us  $noise  cyy* $extras   if lgrdmiss==0 ,ab(sic3) rob cluster(code)
*PCs (data created by file at end of progam)
areg ls zmanagement lpc_emp lp le lm lp_f lp_g lp_un lp_us  le_f le_g le_un le_us  lm_f lm_g lm_un lm_us  $noise  cyy* $extras   if lpc_emp~=. ,ab(sic3) rob cluster(code)
areg ls zmanagement         lp le lm lp_f lp_g lp_un lp_us  le_f le_g le_un le_us  lm_f lm_g lm_un lm_us  $noise  cyy* $extras   if lpc_emp~=. ,ab(sic3) rob cluster(code)


*Text - Factor analysis
u realdata,clear
so code year
factor zlean* zperf* ztalent1 ztalent3 ztalent4 ztalent5 ztalent6 ztalent7 if code~=code[_n-1],pcf
predict factor1
areg ls factor1 lp le lm lp_f lp_g lp_un lp_us  le_f le_g le_un le_us  lm_f lm_g lm_un lm_us  $noise  cyy* $extras  ,ab(sic3) rob cluster(code)


*FN20 and Management on productivity growth rates
areg ls lp le lm lp_f lp_g lp_un lp_us  le_f le_g le_un le_us  lm_f lm_g lm_un lm_us   cyy* if amanagement~=.,ab(code)
predict tfp,res
so code year
by code:gen dtfp=(tfp-tfp[_n-1])
ge lprod=ls-le

by code:gen dlprod=(lprod-lprod[_n-1])
by code:gen dlprod1=dlprod[_n-1]
by code:gen dlprod2=dlprod[_n-2]
by code:gen dlprod3=dlprod[_n-3]

ge avdlprod1=(dlprod1+dlprod2+dlprod3)/3 
replace avdlprod1=(dlprod1+dlprod2)/2 if dlprod3==.
replace avdlprod1=(dlprod2+dlprod3)/2 if dlprod1==.
replace avdlprod1=(dlprod1+dlprod3)/2 if dlprod2==.
replace avdlprod1=dlprod1 if dlprod2==.&dlprod3==.
replace avdlprod1=dlprod2 if dlprod1==.&dlprod3==.
replace avdlprod1=dlprod3 if dlprod1==.&dlprod2==.

areg zmanagement dlprod1 lempm lfirmage public ldegree* mba* uncons ccfr ccge ccuk  reli sen1 day2 day3 day4 day5 timelocal tenurepost countries gender  duration reli aa* cc* $extras   if (code~=code[_n+1]),ab(sic3) 
areg zmanagement avdlprod1 lempm lfirmage public ldegree* mba* uncons ccfr ccge ccuk  reli sen1 day2 day3 day4 day5 timelocal tenurepost countries gender  duration reli aa* cc* $extras   if (code~=code[_n+1]),ab(sic3) 


areg zmanagement dlprod2 lempm lfirmage public ldegree* mba* uncons ccfr ccge ccuk  reli sen1 day2 day3 day4 day5 timelocal tenurepost countries gender  duration reli aa* cc* $extras   if (code~=code[_n+1]),ab(sic3) 
areg zmanagement dlprod3 lempm lfirmage public ldegree* mba* uncons ccfr ccge ccuk  reli sen1 day2 day3 day4 day5 timelocal tenurepost countries gender  duration reli aa* cc* $extras   if (code~=code[_n+1]),ab(sic3) 

areg dtfp amanagement reli sen1 day2 day3 day4 day5 timelocal tenurepost countries gender  duration reli aa* cc* $extras   if year==2003,ab(sic3) 
areg dtfp amanagement reli sen1 day2 day3 day4 day5 timelocal tenurepost countries gender  duration reli aa* cc* $extras   if year>=2001,ab(sic3) 

*Text - Variation of management across country, industry and both
u realdata,clear
so code year
reg amanagement cc* if code!=code[_n-1]
gen sic3c=sic3
replace sic3c=sic3*10 if cty=="uk"
replace sic3c=sic3*100 if cty=="fr"
replace sic3c=sic3*1000 if cty=="gr"
areg amanagement if code!=code[_n-1],ab(sic3c)

*FN27
areg hoursm lindiopen9599 lempm lfirmage public ldegree* mba* uncons ccfr ccge ccuk  $noise  if code~=code[_n+1],ab(sic3)rob cluster(oecdind_cty)
areg hoursm lerner lempm lfirmage public ldegree* mba* uncons ccfr ccge ccuk  $noise  if code~=code[_n+1],ab(sic3)rob cluster(csic)
areg hoursm competition* lempm lfirmage public ldegree* mba* uncons ccfr ccge ccuk  $noise  if code~=code[_n+1],ab(sic3)rob cluster(csic)

*FN28 and Competition and dispersion
u realdata,replace
drop if year==.
so code year
keep if code~=code[_n+1]
ge one=1
egen no_ij=sum(one),by(sic3 cty)
foreach X in zmanagement amanagement {
qui egen `X'_mean=mean(`X'),by(sic3 cty) 
qui egen `X'_sd=sd(`X'),by(sic3 cty) 
ge `X'_cv=`X'_sd/`X'_mean
}

/*do at cell level*/
mac def xvars "zmanagement_cv amanagement_cv   lerner ccus ccuk ccfr ccge no_ij lindiopen9599 lempm lfirmage public ldegree* mba* uncons  gender sen1 tenurep countries day2 day3 day4 day5 timelocal  duration reli  aa*  sic3 sic2"
collapse (mean) $xvars ,by(csic)

areg zmanagement_cv  lindiopen9599 ccus ccuk ccfr if no_ij>3,abs(sic3) cluster(sic3)
areg zmanagement_cv  lerner        ccus ccuk ccfr if no_ij>3,abs(sic3) cluster(sic3)


u realdata,clear
so code year
*FN31
areg zoperations famcontrol50_2ceop lempm lfirmage public ldegree* mba* uncons ccfr ccge ccuk  $noise  famceomiss   if code~=code[_n+1],ab(sic3)rob
areg zmonitoring famcontrol50_2ceop lempm lfirmage public ldegree* mba* uncons ccfr ccge ccuk  $noise  famceomiss   if code~=code[_n+1],ab(sic3)rob
areg ztargets famcontrol50_2ceop lempm lfirmage public ldegree* mba* uncons ccfr ccge ccuk  $noise  famceomiss   if code~=code[_n+1],ab(sic3)rob
areg zincentives famcontrol50_2ceop lempm lfirmage public ldegree* mba* uncons ccfr ccge ccuk  $noise  famceomiss   if code~=code[_n+1],ab(sic3)rob


*FN32 and text on competition and family firms
areg famcontrol50_2ceop competition lempm lfirmage public ldegree* mba* uncons ccfr ccge ccuk  $noise  famceomiss   if code~=code[_n+1]&competitionmiss==0,ab(sic3)rob
areg amanagement famcontrol50_2ceop competition lempm lfirmage public ldegree* mba* uncons ccfr ccge ccuk  $noise  famceomiss   if code~=code[_n+1]&competitionmiss==0,ab(sic3)rob
test famcontrol50_2ceop competition

*FN33
u realdata,clear
areg ls zmanagement law lp le lm lp_f lp_g lp_un lp_us  le_f le_g le_un le_us  lm_f lm_g lm_un lm_us  $noise  cyy* $extras    ,ab(sic3) rob cluster(code)
areg ls zmanagement     lp le lm lp_f lp_g lp_un lp_us  le_f le_g le_un le_us  lm_f lm_g lm_un lm_us  $noise  cyy* $extras   if law~=.  ,ab(sic3) rob cluster(code)

*FN34
areg lpaymanagers management lempm publi cc* if code~=code[_n+1],ab(sic3)


*FN35
u realdata,clear
so code year
keep if code~=code[_n+1]
gen USGE=(cty=="us"|cty=="gr")
*Whole sample
ksmirnov management if management>=1,by(USGE)
*Truncated a 2
ksmirnov management if management>=2,by(USGE)
*Truncated version of column 1, table 6
reg amanagement ccge ccfr ccuk if uncons~=.&amanagement>=2,rob

*FN36
u realdata,clear
so code year
drop if code==code[_n+1]
gen lessthantwo=(amanagement<=2)
gen good=(famcontrol50_2ceop==0&famceomiss==0&competition==3)
replace good=. if famceomiss==1|uncons==.
*Total percentage of firms in the tail
su lessthan
*Breakdown of the tail by types of firms and by country and types of firm
tab good,su(lessthan)
tab good if cty=="us",su(lessthan)
tab good if cty~="us",su(lessthan)

*FN38
su lessthan
su lessthan if competition==3

*FN39
u realdata,clear
so code year
keep if code~=code[_n+1]
tab cceurope  if uncons~=.&emp<=1500,su(emp)

reg amanagement ccge ccfr ccuk public lemp if uncons~=.&emp<=1500,rob
gen ccukfr=(cty=="uk"|cty=="fr")
reg amanagement ccge ccukfr lemp if uncons~=.&public==1,rob


log close

endstop